package com.bwie.service.impl;

import com.bwie.bean.City;
import com.bwie.bean.Course;
import com.bwie.bean.Stu;
import com.bwie.dao.StuDAO;
import com.bwie.service.StuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StuServiceImpl implements StuService {

    @Autowired
    private StuDAO stuDAO;

    @Override
    public List list(Map map) {
        return stuDAO.list(map);
    }

    @Override
    public List<City> listCity(Integer pid) {
        return stuDAO.listCity(pid);
    }

    @Override
    public int delstu(Integer sid) {
        //删除中间表
        stuDAO.delzhong(sid);

        int i=stuDAO.delstu(sid);
        return i;
    }

    @Override
    public List<Course> listcourse() {
        return stuDAO.listcourse();
    }

    @Override
    public int add(Stu stu, Integer[] cids) {
        //添加
        int i=stuDAO.add(stu);
        //添加中间表
        Map map = new HashMap();
        map.put("sid",stu.getSid());
        map.put("cids",cids);

        stuDAO.addzhong(map);
        return i;
    }

    @Override
    public int upda(Stu stu, Integer[] cids) {
        //修改
        int i=stuDAO.upda(stu);
        //修改  先删除中间表
        stuDAO.delzhong(stu.getSid());
        //添加中间表
        Map map = new HashMap();
        map.put("sid",stu.getSid());
        map.put("cids",cids);

        stuDAO.addzhong(map);
        return i;
    }

    @Override
    public Stu hui(Integer sid) {
        return stuDAO.hui(sid);
    }


}


















